﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AllenData;
using AllenNeighborhood.UI;

namespace AllenNeighborhood
{
    public partial class FindAddress : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                 ShowStreetNames();
            }
        }

        protected void FindButton_Click(object sender, EventArgs e)
        {
            var data = new NeighborData();
            if (data.GetNeighbors(StreetNo.Text, Utilities.ParseScreenInt(StreetDropDown.SelectedValue)).Any())
            {
                Response.Redirect(string.Format("~/Secure/NeighborList.aspx?StreetNumber={0}&StreetID={1}", StreetNo.Text, StreetDropDown.SelectedValue));
            }
            else
            {
                Response.Redirect("~/Secure/NeighborAdd.aspx");
            }
        }

        protected void ShowStreetNames()
        {   
            var data = new StreetData();
            List<Street> streets = data.GetAllStreets();

            StreetDropDown.DataSource = streets;
            StreetDropDown.DataValueField = "StreetID";
            StreetDropDown.DataTextField = "Name";
            StreetDropDown.DataBind();
        }

    }
}